//
//  ManufacturerTableViewCell.swift
//  ZNZXSuperMarket
//
//  Created by 四川中农 on 2018/7/26.
//  Copyright © 2018年 四川中农. All rights reserved.
//

import UIKit

typealias BackIntValue = (Int)->Void

class ManufacturerTableViewCell: UITableViewCell {
    @IBOutlet weak var collectionView: UICollectionView!
    
    var seleClosure:BackIntValue!
    var manufacturerArray = [FireSiteModel]()
    
    override func awakeFromNib() {
        super.awakeFromNib()

        let layout = UICollectionViewFlowLayout()
        layout.itemSize = CGSize.init(width: 150, height: 166.5)
        layout.scrollDirection = .horizontal
        layout.sectionInset = UIEdgeInsetsMake(0, 12, 0, 7)
        layout.minimumLineSpacing = 10
        self.collectionView.delegate = self
        self.collectionView.dataSource = self
        self.collectionView.showsHorizontalScrollIndicator = false
        self.collectionView.setCollectionViewLayout(layout, animated: true)
    }

    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)

        // Configure the view for the selected state
    }
    
    func reload(withManufacturerArray array:[FireSiteModel]){
        self.manufacturerArray = array
        self.collectionView.reloadData()
    }
}


extension ManufacturerTableViewCell:UICollectionViewDataSource,UICollectionViewDelegate{
    
    func numberOfSections(in collectionView: UICollectionView) -> Int {
        return 1
    }
    
    func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
        return self.manufacturerArray.count
    }

    func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
        let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "ManufacturerCollectionViewCell", for: indexPath) as! ManufacturerCollectionViewCell
        cell.reload(withModel: self.manufacturerArray[indexPath.row])
        return cell
    }
    
    func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
        self.seleClosure(indexPath.row)
    }
    
}




























